﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Management;
using System.Linq;
using System.Printing;
using System.Reflection;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Discovery;
using System.Text;
using System.Xml;
using System.Xml.Linq;
using System.Xml.Serialization;
using System.Xaml;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Markup;
using System.Windows.Xps;

using HTMLConverter;
using LogClass;
using PrinterCommunication;

namespace Wcf_Print
{
    public class PrintWcfService : IPrint
    {
        Printer prt;
        //private DiscoveryClient discoveryClient;
        //private AnnouncementService announcementService;
        //private ServiceHost announcementServiceHost;

        public PrintWcfService()
        {
        }

        public void Ping(out string s)
        {
           s = "OK";
        }

        public void GetPrinters(out string s)
        {
            s = "";

            PrintServer server = new PrintServer();
            PrintQueueCollection p = server.GetPrintQueues();
            foreach (PrintQueue pq in p)
            {
                s += (ConvertToXml(pq) + "|");
                s += (ConvertToXml(pq.DefaultPrintTicket) + "|");
                s += (ConvertToXml(pq.GetPrintCapabilities()) + "|||");
            }
            LogIt.ForceLog(s);
        }

        public void GetOnePrinter(string sp, out string s)
        {
            s = "<PRINTERS>" + Environment.NewLine;
            PrintServer server = new PrintServer();
            PrintQueueCollection p = server.GetPrintQueues();
            foreach (PrintQueue pq in p)
            {
                if (pq.Name == sp)
                {
                    s += (ConvertToXml(pq) + "|");
                    s += (ConvertToXml(pq.DefaultPrintTicket) + "|");
                    s += ConvertToXml(pq.GetPrintCapabilities());
                    s += (Environment.NewLine + "</PRINTERS>");
                    return;
                }
            }
            s = null;
        }

        public void GetDefaultPrinter(out string s)
        {
            s = "";
            ManagementScope ms = new ManagementScope("\\\\" + Environment.MachineName);
            WqlObjectQuery wqlQuery = new WqlObjectQuery("SELECT * FROM Win32_Printer Where Default = TRUE");
            ManagementObjectSearcher searcher = new ManagementObjectSearcher(wqlQuery);
            foreach (ManagementObject printer in searcher.Get())
            {
                s = printer.ToString();
            }
            if (s != "")
                return;
            wqlQuery = new WqlObjectQuery("SELECT * FROM Win32_Printer");
            searcher = new ManagementObjectSearcher(wqlQuery);
            foreach (ManagementObject printer in searcher.Get())
            {
                s = printer.ToString();
                if (s != "")
                    return;
            }
            if (s == "")
                s = "No Printers found";
        }

        public void PrintText(string jobName, string textType, string stext, string sPrintQueue, string xmlPrintTicket, out string sRet)
        {
            PrintServer server = new PrintServer();
            Printers prts = new Printers();
            PrintQueueCollection p = server.GetPrintQueues();
            PrintQueue pq = null;
            FlowDocument fd = new FlowDocument();

            foreach (PrintQueue ppqq in p)
            {
                if (ppqq.Name == sPrintQueue)
                {
                    pq = ppqq;
                    break;
                }
            }

            if (pq == null)
            {
                sRet = "1";
                return;
            }

            PrintDialog printDlg = new PrintDialog();


            switch (textType)
            {
                case "HtmlText":
                    string HTML = HtmlToXamlConverter.ConvertHtmlToXaml(stext, true).Replace("</Run><Run /><Run>", " ");

                    try
                    {
                        StringReader stringReader = new StringReader(HTML);
                        XmlReaderSettings settings = new XmlReaderSettings();
                        settings.DtdProcessing = DtdProcessing.Parse;
                        XmlReader xmlReader = XmlReader.Create(stringReader, settings);
                        fd = System.Windows.Markup.XamlReader.Load(xmlReader) as FlowDocument;
                    }
                    catch (Exception)
                    {
                        sRet = "3";
                        return;
                    }
                    break;

                case "PlainText":
                    TextRange range = new TextRange(fd.ContentStart, fd.ContentEnd);

                    try
                    {
                        using (MemoryStream txtMemoryStream = new MemoryStream())
                        {
                            using (StreamWriter txtStreamWriter = new StreamWriter(txtMemoryStream))
                            {
                                txtStreamWriter.Write(stext);
                                txtStreamWriter.Flush();
                                txtMemoryStream.Seek(0, SeekOrigin.Begin);
                                range.Load(txtMemoryStream, System.Windows.DataFormats.Text);
                            }
                        }
                        fd.Name = jobName;
                    }
                    catch (Exception)
                    {
                        sRet = "4";
                        return;
                    }
                    break;

                case "RtfText":
                    TextRange rtfRange = new TextRange(fd.ContentStart, fd.ContentEnd);

                    // Exception trap for Stream Reader and MemoryStream, ArgumentException intercept for range.
                    // Load in rtf = null or rtf=""          
                    try
                    {
                        using (MemoryStream rtfMemoryStream = new MemoryStream())
                        {
                            using (StreamWriter rtfStreamWriter = new StreamWriter(rtfMemoryStream))
                            {
                                rtfStreamWriter.Write(stext);
                                rtfStreamWriter.Flush();
                                rtfMemoryStream.Seek(0, SeekOrigin.Begin);

                                rtfRange.Load(rtfMemoryStream, System.Windows.DataFormats.Rtf);
                            }
                        }
                        fd.Name = jobName;
                    }
                    catch (Exception)
                    {
                        sRet = "5";
                        return;
                    }
                    break;
                default:
                    sRet = "2";
                    return;
            }

            pq.UserPrintTicket = GetPrintTicket(xmlPrintTicket);
            Print(pq, fd, jobName);     
            sRet = "0";
        }

        public void ReturnPrintServers(out string xmlServers)
        {
            string sExec = Assembly.GetExecutingAssembly().Location;
            int i = sExec.LastIndexOf("\\");
            string sDir = sExec.Substring(0, i) + "\\Data\\servers.xml";
            StreamReader sr = new StreamReader(sDir);
            xmlServers = sr.ReadToEnd();
            sr.Close();
        }

        private System.Printing.PrintTicket GetPrintTicket(string xmlPrintTicket)
        {
            var v = from s in XElement.Parse(xmlPrintTicket).Elements("PRINTTICKET") select new PrinterCommunication.PrintTicket(s);
            PrinterCommunication.PrintTicket prt = v.First();
            System.Printing.PrintTicket pt = new System.Printing.PrintTicket();
            pt.Collation = (Collation)prt.collation;
            pt.CopyCount = (Nullable<Int32>)prt.copyCount;
            pt.DeviceFontSubstitution = (DeviceFontSubstitution)prt.deviceFontSubstitution;
            pt.Duplexing = (Duplexing)prt.duplexing;
            pt.InputBin = (InputBin)prt.inputBin;
            pt.OutputColor = (OutputColor)prt.outputColor;
            pt.OutputQuality = (OutputQuality)prt.outputQuality;
            System.Printing.PageMediaSize pm;
            if (prt.pageMediaSizeName != "")
            {
                if (prt.pageMediaSizeHeight != null)
                    pm = new System.Printing.PageMediaSize(
                         (System.Printing.PageMediaSizeName)Enum.Parse(typeof(PageMediaSizeName), prt.pageMediaSizeName),
                         (double)prt.pageMediaSizeWidth, (double)prt.pageMediaSizeHeight);
                else
                    pm = new System.Printing.PageMediaSize(
                         (System.Printing.PageMediaSizeName)Enum.Parse(typeof(PageMediaSizeName), prt.pageMediaSizeName));
            }
            else
            {
                if (prt.pageMediaSizeHeight != null)
                    pm = new System.Printing.PageMediaSize((double)prt.pageMediaSizeWidth, (double)prt.pageMediaSizeHeight);
                else
                    pm = null;
            }

            pt.PageMediaSize = pm;
            pt.PageBorderless = (PageBorderless)prt.pageBorderless;
            pt.PageOrder = (PageOrder)prt.pageOrder;
            pt.PageOrientation = (PageOrientation)prt.pageOrientation;
            pt.PageResolution = new PageResolution((int)prt.pageResolutionDpiX,
                                                   (int)prt.pageResolutionDpiY,
                                                   (PageQualitativeResolution)prt.qualitativePageResolution);
            pt.PageScalingFactor = (Nullable<Int32>)prt.pageScalingFactor;
            pt.PagesPerSheet = (Nullable<Int32>)prt.pagesPerSheet;
            pt.PhotoPrintingIntent = (PhotoPrintingIntent)prt.photoPrintingIntent;
            return pt;
        }

        private void Print(PrintQueue pq, FlowDocument fd, string sname)
        {
            TextRange copyDocumentRange = new TextRange(fd.ContentStart, fd.ContentEnd);
            // Create a XpsDocumentWriter object, open a Windows common print dialog.
            // This methods returns a ref parameter that represents information about the dimensions of the printer media.
            XpsDocumentWriter docWriter = PrintQueue.CreateXpsDocumentWriter(pq);
            PageImageableArea ia = pq.GetPrintCapabilities().PageImageableArea;
            System.Printing.PrintTicket pt = pq.UserPrintTicket;
            if (docWriter != null && ia != null)
            {
                DocumentPaginator paginator = ((IDocumentPaginatorSource)fd).DocumentPaginator;
                // Change the PageSize and PagePadding for the document to match the CanvasSize for the printer device.
                paginator.PageSize = new System.Windows.Size((double)pt.PageMediaSize.Width, (double)pt.PageMediaSize.Height);
                Thickness pagePadding = fd.PagePadding;
                if (System.Double.IsNaN(pagePadding.Left))
                    pagePadding.Left = 0;
                if (System.Double.IsNaN(pagePadding.Top))
                    pagePadding.Top = 0;
                if (System.Double.IsNaN(pagePadding.Right))
                    pagePadding.Right = 0;
                if (System.Double.IsNaN(pagePadding.Bottom))
                    pagePadding.Bottom = 0;
                fd.PagePadding =
                    new Thickness(Math.Max(ia.OriginWidth, pagePadding.Left),
                                  Math.Max(ia.OriginHeight, pagePadding.Top),
                                  Math.Max((double)pq.UserPrintTicket.PageMediaSize.Width - (double)(ia.OriginWidth + ia.ExtentWidth), pagePadding.Right),
                                  Math.Max((double)pq.UserPrintTicket.PageMediaSize.Height - (double)(ia.OriginHeight + ia.ExtentHeight), pagePadding.Bottom));
                fd.ColumnWidth = double.PositiveInfinity;
                // Send DocumentPaginator to the printer.
                docWriter.Write(paginator);
            }
        }

        private string ConvertToXml(PrintQueue p)
        {
            string sXml = @"<PRINTER Name=""" + p.Name + @""""; 
            sXml += (" FullName=\"" + p.FullName + @"""");
            sXml += (" HasPaperProblem=\"" + p.HasPaperProblem + @"""");
            sXml += (" HasToner=\"" + p.HasToner + @"""");
            sXml += (" HostingPrintServer=\"" + p.HostingPrintServer + @"""");  
            sXml += (" IsInError=\"" + p.IsInError + @"""");
            sXml += (" IsInitializing=\"" + p.IsInitializing + @"""");
            sXml += (" IsManualFeedRequired=\"" + p.IsManualFeedRequired + @"""");
            sXml += (" IsNotAvailable=\"" + p.IsNotAvailable + @"""");
            sXml += (" IsOffline=\"" + p.IsOffline + @"""");
            sXml += (" IsOutOfMemory=\"" + p.IsOutOfMemory + @"""");
            sXml += (" IsOutOfPaper=\"" + p.IsOutOfPaper + @"""");
            sXml += (" IsOutputBinFull=\"" + p.IsOutputBinFull + @"""");  
            sXml += (" IsPaperJammed=\"" + p.IsPaperJammed + @"""");
            sXml += (" IsPaused=\"" + p.IsPaused + @"""");
            sXml += (" IsTonerLow=\"" + p.IsTonerLow + @"""");
            sXml += (" IsWarmingUp=\"" + p.IsWarmingUp + @"""");
            sXml += (" Location=\"" + p.Location + @"""");
            sXml += (" NeedUserIntervention=\"" + p.NeedUserIntervention + @"""");
            sXml += (" NumberOfJobs=\"" + p.NumberOfJobs + @"""");
            sXml += (" QueueStatus=\"" + p.QueueStatus + @"""");
            sXml += (" ShareName=\"" + p.ShareName + @"""");
            sXml += (" StartTimeOfDay=\"" + p.StartTimeOfDay + @"""");
            sXml += (" UntilTimeOfDay=\"" + p.UntilTimeOfDay + @"""");
            sXml += " />";

            return sXml;
        }

        private string ConvertToXml(System.Printing.PrintTicket prt)
        {
            string sXml = "";
            sXml = @"<PRINTTICKET ";
            sXml += (" Collation=\"" + Convert.ToInt32(prt.Collation) + @"""");
            sXml += (" CopyCount=\"" + prt.CopyCount + @"""");
            sXml += (" DeviceFontSubstitution=\"" + prt.DeviceFontSubstitution + @"""");
            sXml += (" Duplexing=\"" + prt.Duplexing + @"""");
            sXml += (" InputBin=\"" + prt.InputBin + @"""");
            sXml += (" OutputColor=\"" + prt.OutputColor + @"""");
            sXml += (" OutputQuality=\"" + prt.OutputQuality + @"""");
            sXml += (" PageBorderless=\"" + prt.PageBorderless + @"""");
            sXml += (" PageMediaSizeName=\"" + prt.PageMediaSize.PageMediaSizeName + @"""");
            sXml += (" PageMediaSizeHeight=\"" + prt.PageMediaSize.Height + @"""");
            sXml += (" PageMediaSizeWidth=\"" + prt.PageMediaSize.Width + @"""");
            sXml += (" PageOrder=\"" + prt.PageOrder + @"""");
            sXml += (" PageOrientation=\"" + prt.PageOrientation + @"""");
            sXml += (" QualitativePageResolution=\"" + prt.PageResolution.QualitativeResolution + @"""");
            sXml += (" PageResolutionDpiX=\"" + prt.PageResolution.X + @"""");
            sXml += (" PageResolutionDpiY=\"" + prt.PageResolution.Y + @"""");
            sXml += (" PageScalingFactor=\"" + prt.PageScalingFactor + @"""");
            sXml += (" PagesPerSheet=\"" + prt.PagesPerSheet + @"""");
            sXml += (" PhotoPrintingIntent=\"" + prt.PhotoPrintingIntent + @"""");
            sXml += " />";
            return sXml;
        }

        private string ConvertToXml(PrintCapabilities prc)
        {
            string sXml = "<PRINTCAPABILITY ";

            int iCollationCapability = 0;
            if (prc.CollationCapability.Count != 0)
            {
                if (prc.CollationCapability.Contains(Collation.Unknown))
                    iCollationCapability += 1;
                if (prc.CollationCapability.Contains(Collation.Collated))
                    iCollationCapability += 2;
                if (prc.CollationCapability.Contains(Collation.Uncollated))
                    iCollationCapability += 4;
            }
            sXml += (" CollationCapability=\"" + iCollationCapability.ToString() + @"""");

            sXml += (" MaxCopyCount=\"" + prc.MaxCopyCount.ToString() + @"""");

            int iDeviceFontSubstitution = 0;
            if (prc.DeviceFontSubstitutionCapability.Count != 0)
            {
                if (prc.DeviceFontSubstitutionCapability.Contains(DeviceFontSubstitution.Unknown))
                    iDeviceFontSubstitution += 1;
                if (prc.DeviceFontSubstitutionCapability.Contains(DeviceFontSubstitution.Off))
                    iDeviceFontSubstitution += 2;
                if (prc.DeviceFontSubstitutionCapability.Contains(DeviceFontSubstitution.On))
                    iDeviceFontSubstitution += 4;
            }
            sXml += (" DeviceFontSubstitutionCapability=\"" + iDeviceFontSubstitution.ToString() + @"""");

            int iDuplexingCapability = 0;
            if (prc.DuplexingCapability.Count != 0)
            {
                if (prc.DuplexingCapability.Contains(Duplexing.Unknown))
                    iDuplexingCapability += 1;
                if (prc.DuplexingCapability.Contains(Duplexing.OneSided))
                    iDuplexingCapability += 2;
                if (prc.DuplexingCapability.Contains(Duplexing.TwoSidedShortEdge))
                    iDuplexingCapability += 4;
                if (prc.DuplexingCapability.Contains(Duplexing.TwoSidedLongEdge))
                    iDuplexingCapability += 8;
            }
            sXml += (" DuplexingCapability=\"" + iDuplexingCapability.ToString() + @"""");

            int iInputBinCapability = 0;
            if (prc.InputBinCapability.Count != 0)
            {
                if (prc.InputBinCapability.Contains(InputBin.Unknown))
                    iInputBinCapability += 1;
                if (prc.InputBinCapability.Contains(InputBin.AutoSelect))
                    iInputBinCapability += 2;
                if (prc.InputBinCapability.Contains(InputBin.Cassette))
                    iInputBinCapability += 4;
                if (prc.InputBinCapability.Contains(InputBin.Tractor))
                    iInputBinCapability += 8;
                if (prc.InputBinCapability.Contains(InputBin.AutoSheetFeeder))
                    iInputBinCapability += 16;
                if (prc.InputBinCapability.Contains(InputBin.Manual))
                    iInputBinCapability += 32;
            }
            sXml += (" InputBinCapability=\"" + iInputBinCapability.ToString() + @"""");

            int iOutputColorCapability = 0;
            if (prc.OutputColorCapability.Count != 0)
            {
                if (prc.OutputColorCapability.Contains(OutputColor.Unknown))
                    iOutputColorCapability += 1;
                if (prc.OutputColorCapability.Contains(OutputColor.Color))
                    iOutputColorCapability += 2;
                if (prc.OutputColorCapability.Contains(OutputColor.Grayscale))
                    iOutputColorCapability += 4;
                if (prc.OutputColorCapability.Contains(OutputColor.Monochrome))
                    iOutputColorCapability += 8;
            }
            sXml += (" OutputColorCapability=\"" + iOutputColorCapability.ToString() + @"""");

            int iOutputQualityCapability = 0;
            if (prc.OutputQualityCapability.Count != 0)
            {
                if (prc.OutputQualityCapability.Contains(OutputQuality.Unknown))
                    iOutputQualityCapability += 1;
                if (prc.OutputQualityCapability.Contains(OutputQuality.Automatic))
                    iOutputQualityCapability += 2;
                if (prc.OutputQualityCapability.Contains(OutputQuality.Draft))
                    iOutputQualityCapability += 4;
                if (prc.OutputQualityCapability.Contains(OutputQuality.Fax))
                    iOutputQualityCapability += 8;
                if (prc.OutputQualityCapability.Contains(OutputQuality.High))
                    iOutputQualityCapability += 16;
                if (prc.OutputQualityCapability.Contains(OutputQuality.Normal))
                    iOutputQualityCapability += 32;
                if (prc.OutputQualityCapability.Contains(OutputQuality.Photographic))
                    iOutputQualityCapability += 16;
                if (prc.OutputQualityCapability.Contains(OutputQuality.Text))
                    iOutputQualityCapability += 32;
            }
            sXml += (" OutputQualityCapability=\"" + iOutputQualityCapability.ToString() + @"""");

            int iPageBorderlessCapability = 0;
            if (prc.PageBorderlessCapability.Count != 0)
            {
                if (prc.PageBorderlessCapability.Contains(PageBorderless.Unknown))
                    iPageBorderlessCapability = 1;
                if (prc.PageBorderlessCapability.Contains(PageBorderless.Borderless))
                    iPageBorderlessCapability += 2;
                if (prc.PageBorderlessCapability.Contains(PageBorderless.None))
                    iPageBorderlessCapability += 4;
            }
            sXml += (" PageBorderlessCapability=\"" + iPageBorderlessCapability.ToString() + @"""");

            int iPageOrderCapability = 0;
            if (prc.PageOrderCapability.Count != 0)
            {
                if (prc.PageOrderCapability.Contains(PageOrder.Unknown))
                    iPageOrderCapability += 1;
                if (prc.PageOrderCapability.Contains(PageOrder.Standard))
                    iPageOrderCapability += 2;
                if (prc.PageOrderCapability.Contains(PageOrder.Reverse))
                    iPageOrderCapability += 4;
            }
            sXml += (" PageOrderCapability=\"" + iPageOrderCapability.ToString() + @"""");

            int iPageOrientationCapability = 0;
            if (prc.PageOrientationCapability.Count != 0)
            {
                if (prc.PageOrientationCapability.Contains(PageOrientation.Unknown))
                    iPageOrientationCapability += 1;
                if (prc.PageOrientationCapability.Contains(PageOrientation.Landscape))
                    iPageOrientationCapability += 2;
                if (prc.PageOrientationCapability.Contains(PageOrientation.Portrait))
                    iPageOrientationCapability += 4;
                if (prc.PageOrientationCapability.Contains(PageOrientation.ReverseLandscape))
                    iPageOrientationCapability += 8;
                if (prc.PageOrientationCapability.Contains(PageOrientation.ReversePortrait))
                    iPageOrientationCapability += 16;
            }
            sXml += (" PageOrientationCapability=\"" + iPageOrientationCapability.ToString() + @"""");

            int iPageResolutionCapability = 0;
            Nullable<Int32> ipageResolutionCapabilityDpiX = null;
            Nullable<Int32> ipageResolutionCapabilityDpiY = null;

            foreach (PageResolution pageRes in prc.PageResolutionCapability)
            {
                if (pageRes.QualitativeResolution == PageQualitativeResolution.Unknown)
                    iPageResolutionCapability += 1;
                if (pageRes.QualitativeResolution == PageQualitativeResolution.Default)
                {
                    iPageResolutionCapability += 2;
                    ipageResolutionCapabilityDpiX = pageRes.X;
                    ipageResolutionCapabilityDpiY = pageRes.Y;
                }
                if (pageRes.QualitativeResolution == PageQualitativeResolution.Draft)
                {
                    iPageResolutionCapability += 4;
                    ipageResolutionCapabilityDpiX = pageRes.X;
                    ipageResolutionCapabilityDpiY = pageRes.Y;
                }
                if (pageRes.QualitativeResolution == PageQualitativeResolution.High)
                {
                    iPageResolutionCapability += 8;
                    ipageResolutionCapabilityDpiX = pageRes.X;
                    ipageResolutionCapabilityDpiY = pageRes.Y;
                }
                if (pageRes.QualitativeResolution == PageQualitativeResolution.Normal)
                {
                    iPageResolutionCapability += 16;
                    ipageResolutionCapabilityDpiX = pageRes.X;
                    ipageResolutionCapabilityDpiY = pageRes.Y;
                }
                if (pageRes.QualitativeResolution == PageQualitativeResolution.Other)
                {
                    iPageResolutionCapability += 32;
                    ipageResolutionCapabilityDpiX = pageRes.X;
                    ipageResolutionCapabilityDpiY = pageRes.Y;
                }
            }
            sXml += (" PageResolutionCapability=\"" + iPageResolutionCapability.ToString() + @"""");
            sXml += (" PageResolutionCapabilityDpiX=\"" + ipageResolutionCapabilityDpiX.ToString() + @"""");
            sXml += (" PageResolutionCapabilityDpiY=\"" + ipageResolutionCapabilityDpiY.ToString() + @"""");

            if (prc.PageScalingFactorRange != null)
            {
                sXml += (" PageScalingFactorRangeMinimum=\"" + prc.PageScalingFactorRange.MinimumScale.ToString() + @"""");
                sXml += (" PageScalingFactorRangeMaximum=\"" + prc.PageScalingFactorRange.MaximumScale.ToString() + @"""");
            }
            else
            {
                sXml += (" PageScalingFactorRangeMinimum=\"100" + @"""");
                sXml += (" PageScalingFactorRangeMaximum=\"100" + @"""");
            }

            int iPhotoPrintingIntentCapability = 0;
            if (prc.PhotoPrintingIntentCapability.Count != 0)
            {
                if (prc.PhotoPrintingIntentCapability.Contains(PhotoPrintingIntent.Unknown))
                    iPhotoPrintingIntentCapability += 1;
                if (prc.PhotoPrintingIntentCapability.Contains(PhotoPrintingIntent.None))
                    iPhotoPrintingIntentCapability += 2;
                if (prc.PhotoPrintingIntentCapability.Contains(PhotoPrintingIntent.PhotoBest))
                    iPhotoPrintingIntentCapability += 4;
                if (prc.PhotoPrintingIntentCapability.Contains(PhotoPrintingIntent.PhotoDraft))
                    iPhotoPrintingIntentCapability += 8;
                if (prc.PhotoPrintingIntentCapability.Contains(PhotoPrintingIntent.PhotoStandard))
                    iPhotoPrintingIntentCapability += 16;
            }
            sXml += (" PhotoPrintingIntentCapability=\"" + iPhotoPrintingIntentCapability.ToString() + @"""");
            sXml += (" PageImageableAreaOriginHeight=\"" + prc.PageImageableArea.OriginHeight.ToString() + @"""");
            sXml += (" PageImageableAreaOriginWidth=\"" + prc.PageImageableArea.OriginWidth.ToString() + @"""");
            sXml += (" PageImageableAreaExtentHeight=\"" + prc.PageImageableArea.ExtentHeight.ToString() + @"""");
            sXml += (" PageImageableAreaExtentWidth=\"" + prc.PageImageableArea.ExtentWidth.ToString() + @"""");
            sXml += " />";

            return sXml;
        }
    }
}
